<template>
  <a-spin :spinning="confirmLoading">
    <a-card :bordered="false">
      <template v-if="!disableSubmit">
        <a-button slot="extra" @click="handleOk">保存</a-button>
        <a-button slot="extra" type="primary" @click="handleSubmit" style="margin-left: 10px">提交</a-button>
      </template>
      <ex-project-form ref="projectInfo" v-if="model.bizType=='GC'" @ok="submitCallback" :projectId="projectId" :disabled="disableSubmit" />
      <ex-project-cg-form ref="projectInfo"  v-if="model.bizType=='CG'"  @ok="submitCallback" :projectId="projectId" :disabled="disableSubmit" />
    </a-card>
  </a-spin>
</template>
<script>
import ExProjectForm from '@/views/exProject/modules/ExProjectForm.vue'
import ExProjectCgForm from '@/views/exProject/modules/ExProjectCgForm.vue'
import { getAction, httpAction } from '@api/manage'
export default {
  components: {
    ExProjectForm,
    ExProjectCgForm
  },
  data() {
    return {
      projectId: '',
      confirmLoading: false,
      url: {
        queryById: '/exProject/exProject/queryById',
        submitAudit: 'exProject/exProject/submitAudit',
      },
      model: {},
      submiting: false,
      disableSubmit: true,
    }
  },
  created() {
    this.projectId = this.$route.query.projectId
    this.projectName = this.$route.query.projectName
    this.showDetail()
  },
  methods: {
    showDetail() {
      let that = this
      getAction(this.url.queryById, { id: this.projectId }).then((res) => {
        if (res.success) {
          var record = res.result
          that.model = record
          that.disableSubmit = that.model.status != 0 && that.model.status != 3
          this.$nextTick(() => {
            that.$refs['projectInfo'].model = record
            that.$refs['projectInfo'].editAfter()
          })
        }
      })
    },
    handleOk() {
      this.$refs.projectInfo.handleOk()
    },
    submitCallback() {
      var that = this
      if (this.submiting) {
        that.confirmLoading = true
        //提交的动作
        httpAction(this.url.submitAudit + '?id=' + this.model.id, {}, 'post')
          .then((res) => {
            if (res.success) {
              that.$message.success(res.message)
              that.showDetail()
            } else {
              that.$message.warning(res.message)
            }
          })
          .finally(() => {
            that.confirmLoading = false
          })
      }
    },
    handleSubmit() {
      var that = this;
      this.$confirm({
        title: '确认提交',
        content: '确定要提交吗?',
        onOk: function () {
          that.handleOk()
          that.submiting = true
        },
      })
    },
  },
}
</script>

<style>
#components-layout-demo-custom-trigger .trigger {
  font-size: 18px;
  line-height: 64px;
  padding: 0 24px;
  cursor: pointer;
  transition: color 0.3s;
}

#components-layout-demo-custom-trigger .trigger:hover {
  color: #1890ff;
}

#components-layout-demo-custom-trigger .logo {
  height: 32px;
  background: rgba(255, 255, 255, 0.2);
  margin: 16px;
  color: #fff;
  line-height: 32px;
  text-align: center;
}
</style>
